<!DOCTYPE html>
<html>
<head>
    <title>接口注册管理</title>
    <#include "/common/import.ftl" >
    <script type="text/javascript" src="${ctx}/js/utiltools.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#dataCateList').datagrid({
                title: '接口调用列表',
                iconCls: 'icon-ok',
                url: '${ctx!''}/rpc/list!data.action',
                nowrap: false,
                striped: true,
                collapsible: false,
                fitColumns: true,
                pagination: true,
                singleSelect: true,
                rownumbers: true,
                remoteSort: false,
                pageList: [15, 20, 30, 50],
                idField: 'monitoringId',
                columns: [[
                    {
                        field: 'beanId', title: 'beanID', width: 150, sortable: true,
                        formatter: function (value, row) {
                            //var startDate = new Date(value).getTime();
                            var startDate = getTimeStrByDate(value);
                            var stopDate = getTimeStrByDate(row.stopTime);
                            return value + "->" + row.methodKey;
                        }
                    },
                    {field: 'serverAddr', title: '服务地址', width: 80, sortable: true},
                    {
                        field: 'startTime', title: '执行时间', width: 100, sortable: true,
                        formatter: function (value, row) {
                            //var startDate = new Date(value).getTime();
                            var startDate = getTimeStrByDate(value);
                            var stopDate = getTimeStrByDate(row.stopTime);
                            return "start:" + row.startTime + "<br/> stop:" + row.stopTime + "<br>time:" + (stopDate - startDate) + "毫秒";
                        }
                    },
                    {field: 'monitoring1', title: '来源', width: 150, sortable: true},
                    {field: 'reqParams', title: '请求参数', width: 150, sortable: true}
                ]],
                toolbar: [{
                    text: '查找',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#query').window('open');
                    }
                }, '-', {
                    text: '刷新',
                    iconCls: 'icon-reload',
                    handler: function () {
                        $('#dataCateList').datagrid('reload');
                    }
                }
                ]
            });
        });

        // 查找
        function searchCate() {
            var queryParams = $('#dataCateList').datagrid('options').queryParams;
            queryParams.beanId = $('#beanId').val();
            queryParams.beanName = $('#methodKey').val();
            var options = $('#dataCateList').datagrid('getPager').data("pagination").options;
            options.pageNumber = 1;
            options.total = 0;
            options.pageSize = 15;
            $('#dataCateList').datagrid("reload");
            $('#query').window('close');
        }

        // 刷新列表
        function cateReload() {
            $('#dataCateList').datagrid('reload');
        }

        // 判断是否选中一条记录
        function getSelected() {
            var selected = $('#dataCateList').datagrid('getSelected');
            if (selected) {
                return selected;
            } else {
                $.messager.alert('提示', '请选择要操作的数据', 'info');
            }
        }

        /**
         *  var dateStr = "2018-03-19 12:03:46:958";//1521432226958
         alert(getTimeStrByDate(dateStr));
         dateStr = "2018-03-19 12:03:46";
         alert(getTimeStrByDate(dateStr));//1521432226000
         * @param str
         * @returns {number}
         */
        function getTimeStrByDate(str) {
            if (str.split(":").length == 4) {
                var lastYIndex = str.lastIndexOf(":");
                var dateObj = new Date(str.substring(0, lastYIndex));
                var sss = str.substring(str.lastIndexOf(":") + 1);
                var dateObj2 = new Date(dateObj.getFullYear(), dateObj.getMonth(), dateObj.getDate(), dateObj.getHours(), dateObj.getMinutes(), dateObj.getUTCSeconds(), sss);
                return dateObj2.getTime();
            } else {
                var dateObj = new Date(str);
                return dateObj.getTime();
            }
        }
    </script>
</head>
<body>
<table id="dataCateList"></table>

<!-- 查询窗口 -->
<div id="query" class="easyui-window" title="查询" style="padding:0px;width:400px;height:250;"
     iconCls="icon-search" closed="true" maximizable="false" minimizable="false"
     collapsible="false">
    <table class="datagrid-body">
        <tr>
            <td class="datagrid-header">beanID：</td>
            <td><input type="text" id="beanId" name="beanId" size="30" value=""/></td>
        </tr>
        <tr>
            <td class="datagrid-header">调用方法：</td>
            <td><input type="text" id="methodKey" name="methodKey" size="30" value=""/></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><a href="#" class="easyui-linkbutton"
                                              iconCls="icon-search" onClick="searchCate();">查找</a>
            </td>
        </tr>
    </table>
</div>
</body>
</html>